<%@ page import="com.wuming.caiwu.security.SecurityHander" %><%--
  Created by IntelliJ IDEA.
  User: hanfei
  Date: 18/6/27
  Time: 下午3:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${allServerPath}static/css/bootstrap.min.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/style.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <style>
        .tab_zp td span {
            font-weight: bold;
            color: #003399;
        }

        ::-moz-placeholder {
            color: #d4d4d4;
        }

        ::-webkit-input-placeholder {
            color: #d4d4d4;
        }

        :-ms-input-placeholder {
            color: #d4d4d4;
        }

        .layui-upload-img{
            width: 82px;
            height: 82px;
        }
        .layui-upload button{
            background: none;
            position: absolute;
            top: 10px;
            left: 55px;
            width: 82px;
            height: 82px;
            margin: 0;
            padding: 0;
        }
        .layui-upload-list img{
            display: block;
            margin: 0 auto;
        }

    </style>
</head>
<body>
<div style="padding: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>商品基本信息</legend>
    </fieldset>

    <form class="layui-form" action="" id="productForm">
        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">商品名</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="productName" placeholder="请输入商品名" autocomplete="off"
                                   class="layui-input"
                                   value="${product['productName']}">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">品牌</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="productBrand" value="${product['productBrand']}" id="productBrand"
                                   autocomplete="off" class="layui-input" placeholder="请输入品牌">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">净含量</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="productHanliang" value="${product['productHanliang']}" placeholder="请输入净含量"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">保质期</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="qualityPeriod" value="${product['qualityPeriod']}" placeholder="请输入保质期"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <span>天</span>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">发货时间</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="deliveryTime" value="${product['deliveryTime']}" placeholder="请输入发货时间"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <span>天</span>
                </div>
            </div>
<shiro:hasAnyRoles name="super:manage">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">价格</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="price" value="${product['price']}" placeholder="请输入价格"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <span>元</span>
                </div>
            </div>
</shiro:hasAnyRoles>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 120px">商品分类</label>

                        <div class="layui-input-inline">
                            <select name="productCategoryId" id="productCategoryId" lay-verify="productCategoryId">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
<shiro:hasAnyRoles name="super:manage">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label">是否热卖商品</label>
                    <div class="form-group layui-input-inline">
                        <select id="isHot" name="isHot" lay-filter="isHot">
                            <option value=""></option>
                            <option value="0">不是</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>
            </div>
</shiro:hasAnyRoles>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">库存</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="stock" value="${product['stock']}" placeholder="请输入库存"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <span>件</span>
                </div>
            </div>

            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">商家编码</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="factoryCode" value="${product['factoryCode']}" placeholder="请输入商家编码"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <%--<div class="layui-col-xs4">--%>
                <%--<div class="layui-form-item">--%>
                    <%--<div class="layui-inline">--%>
                        <%--<label class="layui-form-label">市场价</label>--%>

                        <%--<div class="form-group layui-input-inline">--%>
                            <%--<input type="text" name="marketPrice" value="${product['marketPrice']}" placeholder="请输入市场价"--%>
                                   <%--autocomplete="off"--%>
                                   <%--class="layui-input">--%>
                        <%--</div>--%>
                    <%--</div>--%>
                    <%--<span>元</span>--%>
                <%--</div>--%>
            <%--</div>--%>

            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">批发价</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="tradePrice" value="${product['tradePrice']}" placeholder="请输入批发价"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <span>元</span>
                </div>
            </div>
                <shiro:hasAnyRoles name="super:manage">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">股东门店采购价</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="gudongTradePrice" value="${product['gudongTradePrice']}" placeholder="请输入股东门店采购价"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <span>元</span>
                </div>
            </div>
            </shiro:hasAnyRoles>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">销量</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="sale" value="${product['sale']}" placeholder="请输入销量"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <span>件</span>
                </div>
            </div>

            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 120px">配送规则</label>

                        <div class="layui-input-inline">
                            <select name="shipRuleId" id="shipRuleId" lay-verify="shipRuleId">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <shiro:hasAnyRoles name="super:manage">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 120px">订单配送规则</label>

                        <div class="layui-input-inline">
                            <select name="orderShipRuleId" id="orderShipRuleId" lay-verify="orderShipRuleId">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 120px">是否分销商品</label>

                            <div class="layui-input-inline">
                                <select name="isPromoterGood" id="isPromoterGood" lay-verify="isPromoterGood">
                                    <option value=""></option>
                                    <option value="0">不是</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <%--<div class="layui-col-xs4">--%>
                    <%--<div class="layui-form-item">--%>
                        <%--<div class="layui-inline">--%>
                            <%--<label class="layui-form-label">一级佣金</label>--%>

                            <%--<div class="form-group layui-input-inline">--%>
                                <%--<input type="text" name="commissionRatio" value="${product['commissionRatio']}" placeholder="请输入一级佣金"--%>
                                       <%--autocomplete="off"--%>
                                       <%--class="layui-input">--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <%--<span>%</span>--%>
                    <%--</div>--%>
                <%--</div>--%>

                <%--<div class="layui-col-xs4">--%>
                    <%--<div class="layui-form-item">--%>
                        <%--<div class="layui-inline">--%>
                            <%--<label class="layui-form-label">二级佣金</label>--%>

                            <%--<div class="form-group layui-input-inline">--%>
                                <%--<input type="text" name="twoCommissionRatio" value="${product['twoCommissionRatio']}" placeholder="请输入二级佣金"--%>
                                       <%--autocomplete="off"--%>
                                       <%--class="layui-input">--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <%--<span>%</span>--%>
                    <%--</div>--%>
                <%--</div>--%>
            </div>
        </shiro:hasAnyRoles>

        <c:if test="${product['id'] != null}">
        <div class="layui-row">
            <div class="layui-col-xs12">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">商品主图</label>
                        <div class="layui-upload layui-input-inline imageWidth">
                            <div class="layui-upload-list">
                                <button type="button" class="layui-btn" id="productMainPic"></button>
                                <c:if test="${product['productMainPic'] != null}">
                                    <img class="layui-upload-img" src="${product['productMainPic']}"
                                         id="productMainPicImg">
                                </c:if>
                                <c:if test="${product['productMainPic'] == null}">
                                    <img class="layui-upload-img" src="${allServerPath}/static/images/insure/more.png"
                                         id="productMainPicImg">
                                </c:if>
                                <p style="text-align: center;margin-top: 10px;">主图</p>
                            </div>
                        </div>
                        <div class="layui-upload layui-input-inline imageWidth">
                            <div class="layui-upload-list">
                                <button type="button" class="layui-btn" id="productPic1"></button>
                                <c:if test="${product['productPic1'] != null}">
                                    <img class="layui-upload-img" src="${product['productPic1']}"
                                         id="productPic1Img">
                                </c:if>
                                <c:if test="${product['productPic1'] == null}">
                                    <img class="layui-upload-img" src="${allServerPath}/static/images/insure/more.png"
                                         id="productPic1Img">
                                </c:if>
                                <p style="text-align: center;margin-top: 10px;">图片1</p>
                            </div>
                        </div>
                        <div class="layui-upload layui-input-inline imageWidth">
                            <div class="layui-upload-list">
                                <button type="button" class="layui-btn" id="productPic2"></button>
                                <c:if test="${product['productPic2'] != null}">
                                    <img class="layui-upload-img" src="${product['productPic2']}"
                                         id="productPic2Img">
                                </c:if>
                                <c:if test="${product['productPic2'] == null}">
                                    <img class="layui-upload-img" src="${allServerPath}/static/images/insure/more.png"
                                         id="productPic2Img">
                                </c:if>
                                <p style="text-align: center;margin-top: 10px;">图片2</p>
                            </div>
                        </div>
                        <div class="layui-upload layui-input-inline imageWidth">
                            <div class="layui-upload-list">
                                <button type="button" class="layui-btn" id="productPic3"></button>
                                <c:if test="${product['productPic3'] != null}">
                                    <img class="layui-upload-img" src="${product['productPic3']}"
                                         id="productPic3Img">
                                </c:if>
                                <c:if test="${product['productPic1'] == null}">
                                    <img class="layui-upload-img" src="${allServerPath}/static/images/insure/more.png"
                                         id="productPic3Img">
                                </c:if>
                                <p style="text-align: center;margin-top: 10px;">图片3</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </c:if>


        <c:if test="${product['id'] != null}">
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">商品图片</label>
                            <div class="layui-upload layui-input-inline imageWidth">
                                <div class="layui-upload-list">
                                    <button type="button" class="layui-btn" id="qualityReport"></button>
                                    <c:if test="${product['qualityReport'] != null}">
                                        <img class="layui-upload-img" src="${product['qualityReport']}"
                                             id="qualityReportImg">
                                    </c:if>
                                    <c:if test="${product['qualityReport'] == null}">
                                        <img class="layui-upload-img" src="${allServerPath}/static/images/insure/more.png"
                                             id="qualityReportImg">
                                    </c:if>
                                    <p style="text-align: center;margin-top: 10px;">质检报告</p>
                                </div>
                            </div>
                            <div class="layui-upload layui-input-inline imageWidth">
                                <div class="layui-upload-list">
                                    <button type="button" class="layui-btn" id="packTag"></button>
                                    <c:if test="${product['packTag'] != null}">
                                        <img class="layui-upload-img" src="${product['packTag']}"
                                             id="packTagImg">
                                    </c:if>
                                    <c:if test="${product['packTag'] == null}">
                                        <img class="layui-upload-img" src="${allServerPath}/static/images/insure/more.png"
                                             id="packTagImg">
                                    </c:if>
                                    <p style="text-align: center;margin-top: 10px;">包装标签</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </c:if>

        <div class="layui-row">
            <div class="layui-col-xs12">
                <div class="layui-form-item">
                    <label class="layui-form-label">商品详情</label>

                    <div class="form-group">
                        <textarea id="productDetail" style="width: 50%" name="productDetail">${product['productDetail']}</textarea>
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" name="storeId" value="<%=SecurityHander.getCurrentUserId()%>">
        <input type="hidden" name="id" value="${product['id']}"/>
    </form>
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-form-item">
                <button class="layui-btn" type="button" name="btnSave" id="btnSave" lay-filter="btnSave">保存商品信息
                </button>
                <shiro:hasAnyRoles name="super:manage">
                <button class="layui-btn" type="button" name="btnVerify" id="btnVerify" lay-filter="btnVerify">审核通过
                </button>
                </shiro:hasAnyRoles>
                <shiro:hasAnyRoles name="super:manage">
                    <button class="layui-btn" type="button" name="btnUnderProduct" id="btnUnderProduct" lay-filter="btnUnderProduct">下架商品
                    </button>
                </shiro:hasAnyRoles>
            </div>
        </div>
    </div>

</div>

<script src="${allServerPath}static/layui/layui/layui.js" charset="utf-8"></script>
<script src="${allServerPath}static/js/jquery-2.1.4.min.js" charset="utf-8"></script>
<script src="${allServerPath}static/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${allServerPath}static/js/bootstrapValidator.js"></script>
<script type="text/javascript" src="${allServerPath}static/js/common/date-util.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.config({
        base: '${allServerPath}static/layui/build/js/'
    }).extend({
        tinymce: 'tinymce/tinymce'
    }).use(['layer', 'form', 'laydate', 'jquery', 'upload','tinymce'], function () {
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
            , $ = layui.jquery
            , tinymce = layui.tinymce
            , upload = layui.upload;


        $(document).ready(function () {
            getAllProductCategory();
            getShipRule();
            getOrderShipRule();
        });

        function getAllProductCategory() {
            $.ajax({
                type: 'get',
                url: '${allServerPath}web/productcategory/getAll.htmls',
                data: {
                },
                dataType: 'JSON',
                success: function (obj) {
                    if (obj.success) {
                        $.each(obj.data, function (index, item) {
                            var s = "<option value='" + item.id + "'>" + item.name + "</option>";
                            $("#productCategoryId").append(s);
                        })
                        var productCategoryId = '${product.productCategoryId}';
                        $("#productCategoryId").val(productCategoryId);
                        form.render();
                    }
                }
            });
        }

        function getShipRule() {
            $.ajax({
                type: 'get',
                url: '${allServerPath}web/productship/get.htmls',
                data: {
                    "storeId": "<%=SecurityHander.getCurrentUserId()%>"
                },
                dataType: 'JSON',
                success: function (obj) {
                    if (obj.success) {
                        var s = "<option value='" + obj.data.id + "'>" + obj.data.ruleName + "</option>";
                        $("#shipRuleId").append(s);
                        var shipRuleId = '${product.shipRuleId}';
                        $("#shipRuleId").val(shipRuleId);
                        form.render();
                    }
                }
            });
        }

        function getOrderShipRule() {
            $.ajax({
                type: 'get',
                url: '${allServerPath}web/ordership/get.htmls',
                data: {
                },
                dataType: 'JSON',
                success: function (obj) {
                    if (obj.success && obj.data.id != null) {
                        var s = "<option value='" + obj.data.id + "'>" + obj.data.ruleName + "</option>";
                        $("#orderShipRuleId").append(s);
                        var orderShipRuleId = '${product.orderShipRuleId}';
                        $("#orderShipRuleId").val(orderShipRuleId);
                        form.render();
                    }
                }
            });
        }

        var qru = upload.render({
            elem: '#qualityReport'  /*根据绑定id，打开本地图片*/
            , url: '${allServerPath}web/pms/saveProductImg.htmls' /*上传后台接受接口*/
            , auto: true  /*true为选中图片直接提交，false为不提交根据bindAction属性上的id提交*/
            , data: {
                memberId: '<%=SecurityHander.getCurrentUserId()%>',
                productId: '${product.id}',
                type: 0
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#qualityReportImg').attr('src', res.data); //图片链接（base64）
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                layer.msg("上传失败.");
            }
        });

        var ptu = upload.render({
            elem: '#packTag'  /*根据绑定id，打开本地图片*/
            , url: '${allServerPath}web/pms/saveProductImg.htmls' /*上传后台接受接口*/
            , auto: true  /*true为选中图片直接提交，false为不提交根据bindAction属性上的id提交*/
            , data: {
                memberId: '<%=SecurityHander.getCurrentUserId()%>',
                productId: '${product.id}',
                type: 1
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#packTagImg').attr('src', res.data); //图片链接（base64）
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                layer.msg("上传失败.");
            }
        });

        var mainpic = upload.render({
            elem: '#productMainPic'  /*根据绑定id，打开本地图片*/
            , url: '${allServerPath}web/pms/saveProductImg.htmls' /*上传后台接受接口*/
            , auto: true  /*true为选中图片直接提交，false为不提交根据bindAction属性上的id提交*/
            , data: {
                memberId: '<%=SecurityHander.getCurrentUserId()%>',
                productId: '${product.id}',
                type: 2
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#productMainPicImg').attr('src', res.data); //图片链接（base64）
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                layer.msg("上传失败.");
            }
        });

        var pic1 = upload.render({
            elem: '#productPic1'  /*根据绑定id，打开本地图片*/
            , url: '${allServerPath}web/pms/saveProductImg.htmls' /*上传后台接受接口*/
            , auto: true  /*true为选中图片直接提交，false为不提交根据bindAction属性上的id提交*/
            , data: {
                memberId: '<%=SecurityHander.getCurrentUserId()%>',
                productId: '${product.id}',
                type: 3
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#productPic1Img').attr('src', res.data); //图片链接（base64）
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                layer.msg("上传失败.");
            }
        });

        var pic2 = upload.render({
            elem: '#productPic2'  /*根据绑定id，打开本地图片*/
            , url: '${allServerPath}web/pms/saveProductImg.htmls' /*上传后台接受接口*/
            , auto: true  /*true为选中图片直接提交，false为不提交根据bindAction属性上的id提交*/
            , data: {
                memberId: '<%=SecurityHander.getCurrentUserId()%>',
                productId: '${product.id}',
                type: 4
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#productPic2Img').attr('src', res.data); //图片链接（base64）
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                layer.msg("上传失败.");
            }
        });

        var pic3 = upload.render({
            elem: '#productPic3'  /*根据绑定id，打开本地图片*/
            , url: '${allServerPath}web/pms/saveProductImg.htmls' /*上传后台接受接口*/
            , auto: true  /*true为选中图片直接提交，false为不提交根据bindAction属性上的id提交*/
            , data: {
                memberId: '<%=SecurityHander.getCurrentUserId()%>',
                productId: '${product.id}',
                type: 5
            }
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    $('#productPic3Img').attr('src', res.data); //图片链接（base64）
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                layer.msg("上传失败.");
            }
        });

        //日期
        var isHot = '${product.isHot}';

        if ('' == isHot) {
            $("#isHot").find("option[value='0']").attr("selected", true);
        } else {
            $("#isHot").val(isHot);
        }

        var isPromoterGood = '${product.isPromoterGood}';

        if ('' == isPromoterGood) {
            $("#isPromoterGood").find("option[value='0']").attr("selected", true);
        } else {
            $("#isPromoterGood").val(isPromoterGood);
        }

        form.render();



        //使用tinymce渲染
        var productDetail = tinymce.render({
            elem:"#productDetail"
            ,height:600
            ,width:'50%'
            ,images_upload_url:'${allServerPath}web/pms/uploadImg.htmls'
        })

        $("button[name='btnSave']").click(function () {
            var productDetail = tinyMCE.get('productDetail').getContent();;
            console.log(productDetail);
            $("#productDetail").html(productDetail);
            $("#productForm").data("bootstrapValidator").resetForm();
            $("#productForm").bootstrapValidator('validate');
            if ($("#productForm").data('bootstrapValidator').isValid()) {
                $.ajax({
                    type: 'post',
                    url: '${allServerPath}web/pms/save.htmls',
                    data: $("#productForm").serialize(),
                    dataType: 'JSON',
                    success: function (data) {
                        if (data.success) {
                            $("input[name='id']").val(data.data);
                            layer.msg("保存成功.");
                        } else {
                            layer.msg(data.message);
                        }
                    },
                    error: function () {
                        layer.msg("保存失败.");
                    }
                });
            }
        });

        $("button[name='btnVerify']").click(function () {
            $.ajax({
                type: 'post',
                url: '${allServerPath}web/pms/verify.htmls',
                data: {
                    id: '${product.id}'
                },
                dataType: 'JSON',
                success: function (data) {
                    if (data.success) {
                        layer.msg("审核成功.");
                    } else {
                        layer.msg(data.message);
                    }
                },
                error: function () {
                    layer.msg("保存失败.");
                }
            });
        });

        $("button[name='btnUnderProduct']").click(function () {
            $.ajax({
                type: 'post',
                url: '${allServerPath}web/pms/underProduct.htmls',
                data: {
                    id: '${product.id}'
                },
                dataType: 'JSON',
                success: function (data) {
                    if (data.success) {
                        layer.msg("下架成功.");
                    } else {
                        layer.msg(data.message);
                    }
                },
                error: function () {
                    layer.msg("保存失败.");
                }
            });
        });

        $('#productForm')
            .bootstrapValidator({
                live: 'disabled',//验证时机
                message: 'This value is not valid',
                submitButtons: '#btnSave',//指定提交按钮
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    productName: {
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            }
                        }
                    },
                    certNo: {
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            },
                            stringLength: {
                                min: 15,
                                max: 18,
                                message: '请输入正确身份证号'
                            },
                            regexp: {
                                regexp: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
                                message: '请输入正确身份证号'
                            }
                        }
                    },
                    mobile: {
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            },
                            stringLength: {
                                min: 11,
                                max: 11,
                                message: '请输入正确手机号码'
                            },
                            regexp: {
                                regexp: /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/,
                                message: '请输入正确手机号码'
                            }
                        }
                    },
                }
            });
    });
</script>
</body>
</html>
